package com.RedRiver.hospitalsystem.personal_service.app.controller;


import com.RedRiver.hospitalsystem.personal_service.infra.model.Worker;
import com.RedRiver.hospitalsystem.personal_service.service.Form.*;
import com.RedRiver.hospitalsystem.personal_service.service.WorkerService;
import com.RedRiver.hospitalsystem.personal_service.service.info.WorkerPageInfo;
import com.RedRiver.hospitalsystem.result.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/worker")
@Api(tags = "工作人员管理接口")
public class WorkerController {

    @Autowired
    private WorkerService workerService;

    @ApiOperation("分页查询所有工作员工")
    @PostMapping("/findAllWorker")
    public Result findPageAllWorker(@RequestBody PageForm form){
        IPage<WorkerPageInfo> byPage = workerService.findAllWorker(form);
        return  Result.getInstance(IPage.class).setMsg("分页成功").setData(byPage);
    }

    @ApiOperation("根据id查询工作人员")
    @PostMapping("/findWorkerById/{id}")
    public Result findWorkerById(@PathVariable("id") Integer id){
        Worker worker_id = workerService.getOne(new QueryWrapper<Worker>().eq("worker_id", id));
        if (worker_id==null) return Result.getInstance(Worker.class).setMsg("查询失败,该id下没有员工").setData(worker_id);
        return Result.getInstance(Worker.class).setMsg("查询成功").setData(worker_id);
    }

    @ApiOperation("根据姓名查询工作人员")
    @PostMapping("/findAllWorkerByName")
    public Result findPageAllWorkerByName(@RequestBody WorkerNamePageForm form){
        IPage<WorkerPageInfo> byPage = workerService.findPageAllWorkerByWorkerName(form);
        return  Result.getInstance(IPage.class).setMsg("分页成功").setData(byPage);
    }

    @ApiOperation("根据部门id分页查询该部门下所有工作员工")
    @PostMapping("/findAllWorkerByDepartmentId")
    public Result findPageAllWorkerByDepartmentId(@RequestBody WorkerPageForm form){
        IPage<WorkerPageInfo> byPage = workerService.findAllWorkerByDepartmentId(form);
        return  Result.getInstance(IPage.class).setMsg("分页成功").setData(byPage);
    }

    @ApiOperation("根据性别分页查询该性别的所有工作人员")
    @PostMapping("/findAllWorkerByWorkerSex")
    public Result findPageAllWorkerByWorkerSex(@RequestBody WorkerSexPageForm form){
        IPage<WorkerPageInfo> byPage = workerService.findAllWorkerByWorkerSex(form);
        return  Result.getInstance(IPage.class).setMsg("分页成功").setData(byPage);
    }

    @ApiOperation("新增工作人员")
    @PostMapping("/createWorker")
    public Result createWorker(@RequestBody WorkerForm workerForm){
        return workerService.addWorker(workerForm);
    }

    @ApiOperation("修改工作人员信息")
    @PostMapping("/updateWorker")
    public Result updateWorker(@RequestBody NewUpdateWorker newUpdateWorker){
        return workerService.updateNewWorker(newUpdateWorker);
    }

    @ApiOperation("根据id删除工作人员信息")
    @PostMapping("/delWorker/{workerId}")
    public Result delWorkerById(@PathVariable("workerId") Integer workerId){
        return workerService.deleteWorkerById(workerId);
    }

}

